package page.transport;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.ListChoice;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.CompoundPropertyModel;

import app.WebApp;
import entity.Binding;
import entity.Route;
import entity.Transport;
import dao.BindingDao;
import dao.RouteDao;
import dao.TransportDao;

public class RoutePage extends WebPage {

	public RoutePage(final Route route) {
		super();

		final Form<Route> form = new Form<Route>("form", new CompoundPropertyModel<Route>(route));
		add(form);

		form.add(new TextField<String>("start"));
		form.add(new TextField<String>("end"));
		form.add(new SubmitLink("save") {
			@Override
			public void onSubmit() {
				super.onSubmit();

				Binding bind = new Binding();
				final RouteDao rDao = new RouteDao(WebApp.DATA_XML_FOLDER);
				final BindingDao bDao = new BindingDao(WebApp.DATA_XML_FOLDER);
				if (route.getId() == null) {
					rDao.saveNew(route);
					bind.setBind(route.getId());
					bind.setRoute(route.getStart()+" "+route.getEnd());
					bDao.saveNew(bind);
				} else {
					
				}
				setResponsePage(new RouteListPage());
			}
		});

		form.add(new Link("cancel") {
			@Override
			public void onClick() {
				setResponsePage(new RouteListPage());
			}
		});
	}
}